/*************************************************************************
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ************************************************************************/


/**
 * @file
 * rtmp.h
 *
 * @author
 * Ales Podskalsky (<a href="mailto:podskale@fel.cvut.cz">podskale@fel.cvut.cz</a>)
 * Pavel Hasenohrl (<a href="mailto:hasenpav@fel.cvut.cz">hasenpav@fel.cvut.cz</a>)
 *
 * @brief
 * Class provides connector to RTMP library.
 */

#ifndef _RTMP_H
#define _RTMP_H

#include <vector>

#include <sys/types.h>
//#include <sys/socket.h>
//#include <unistd.h>
//#include <netinet/in.h>

#include "rtmp/crtmpprotocol.h"
#include "cconnectinfo.h"
#include "cdialinfo.h"

class CRtmp {
    public:
        enum MsgType { RTMP_UNDEFINED, RTMP_STREAM, RTMP_COMMAND, RTMP_DIAL, RTMP_HANG_OUT, RTMP_TCP_END };


    public:
        CRtmp(int iSocket);
        ~CRtmp();

        void Init(fd_set *pRead, fd_set *pWrite);
        void SetFd();
        bool IsAlive();

        bool Handshake();
        bool GetConnectInfo(CConnectInfo &conInfo);
        bool SetConnected();

        bool CheckInput();
        CRtmp::MsgType  GetMessageCode();
        bool ProcessMessage();
        bool CallAccepted();


        bool GetDialInfo(CDialInfo &dinfo);
        bool GetStream(std::string &strStream, int &iTimestamp);
        bool SendStream(const std::string &strStream, int iTimestamp);
        bool SendBye();
        bool SendRejected();

     private:
        int m_iSocket;
        int m_iTransID;
        fd_set *m_pRead, *m_pWrite;
        CRtmpProtocol m_RtmpProtocol;
        CRtmpMsgCreator rtmpMsgGenerator;
        CRtmpMessage m_RtmpMsg;
        vector<int> m_vStreamsID;

        bool m_bStreamSent;
    };

#endif

